/**
 * 购物车
 */
import React, { Component } from 'react'
import $http from '../../Utils/request'
import storage from '../../Utils/storage'
import { Table } from 'antd'
import { connect } from 'react-redux'

const columns = [
  {
    title: '购物车id',
    dataIndex: 'shopCartID',
    key: 'shopCartID',
  },
  {
    title: '商品id',
    dataIndex: 'productId',
    key: 'productId',
  },
  {
    title: '提供商',
    dataIndex: 'branchName',
    key: 'branchName',
  },{
    title: '数量',
    dataIndex: 'quantity',
    key: 'quantity',
  },{
    title: '新增日期',
    dataIndex: 'createTime',
    key: 'createTime',
  },
];
class ShoppingCart extends Component {

  constructor (props) {
    super(props);
    this.state = {
      cartArray : [],
    }
  }
  //创建钩子函数
  componentDidMount () {
    const { userTokenInfo } = this.props

    console.log('storage.get("token")-->',storage.get("token"))
    console.log('userTokenInfo===>===>',userTokenInfo)
    //创建请求头文件
    let config = {}
    if(storage.get("token") !== null){
      config = {
        headers:
          {'Content-Type': 'application/json',
            'token':storage.get("token").data
          }
      }
    }else{
      config = {
        headers:
          {'Content-Type': 'application/json'}
      }
    }
    //请求后台查询数据
    $http.get(
      "http://localhost/mall-basic-service/basic/shoppingCart/queryShoppingCartToUserId",
      config).then((response)=>
    {
      debugger
      console.log('response.data.data',response.data.data)
      this.setState({
        cartArray : response.data.data
      })
    })
  }

  render () {
    return (
      <div className={'bodyDiv'}>
        <Table dataSource={this.state.cartArray} columns={columns} />
      </div>
    )
  }
}
const mapStateToProps = (state) =>{
  return {
    carts: state.get('cartNum'),
    userTokenInfo: state.get('userTokenInfo'),
  }
}
export default connect(mapStateToProps)(ShoppingCart)
